package com.qst.crop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.crop.dao.QuestionDao;
import com.qst.crop.entity.Question;
import com.qst.crop.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService {
    private static Integer pageSize=10;
    @Autowired
    private QuestionDao questionDao;
    @Override
    public Question selectById(Integer id) {
        Question question = new Question();
        question.setId(id);
        return questionDao.selectByExample(question);
    }

    @Override
    public void insert(Question question) {
           questionDao.insertSelective(question);
    }

    @Override
    public PageInfo<Question> selectByKeys(String keys, Integer pageNum){
        PageHelper.startPage(pageNum, pageSize);
        List<Question> questions = questionDao.selectAllByKeys(keys);
        PageInfo<Question> questionPageInfo = new PageInfo<>(questions);
        return questionPageInfo;
    }
}

